//
//  UIButton+CPJButton.m
//  成品家
//
//  Created by YYY on 2017/3/3.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

#import "UIButton+CPJButton.h"

@implementation UIButton (CPJButton)

//UIButton内容宽、高自适应
-(CGSize)boundingRectWithSize:(CGSize)size
{
    NSDictionary *attribute = @{NSFontAttributeName : self.titleLabel.font};
    CGSize retSize = [self.currentTitle boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading | NSStringDrawingTruncatesLastVisibleLine attributes:attribute context:nil].size;
    return retSize;
}

//文字按钮
-(void)setTitleStr:(NSString *)titleStr frame:(CGRect)frame titleColor:(UIColor *)titleColor fontSize:(CGFloat)fontSize
{
    self.frame = frame;
    [self setTitle:titleStr forState:UIControlStateNormal];
    self.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    [self setTitleColor:titleColor forState:UIControlStateNormal];
}

//图片按钮
-(void)setImageStr:(NSString *)imageStr frame:(CGRect)frame
{
    self.frame = frame;
    [self setImage:[UIImage imageNamed:imageStr] forState:UIControlStateNormal];
}

//圆角按钮
-(void)setRadiusTitleStr:(NSString *)titleStr frame:(CGRect)frame titleColor:(UIColor *)titleColor fontSize:(CGFloat)fontSize radius:(CGFloat)radius borderColor:(UIColor *)borderColor borderWidth:(CGFloat)borderWidth
{
    self.frame = frame;
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = radius;
    self.layer.borderColor = borderColor.CGColor;
    self.layer.borderWidth = borderWidth;
    [self setTitle:titleStr forState:UIControlStateNormal];
    self.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    [self setTitleColor:titleColor forState:UIControlStateNormal];
}

@end
